/*
 *   Copyright 2012, Thomas Kerber
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package milk.skimmed;

/**
 * A key denotes a class, method or field which may hint at a unique
 * requirement.
 * 
 * Keys are associated with jarps and if a new mod requires anything supplied
 * by this key, the associated jarp is added as a req.
 * @author Thomas Kerber
 * @version 1.0.0
 */
public class Key{
    
    /**
     * The type of key.
     * @author Thomas Kerber
     * @version 1.0.0
     */
    public static enum KeyType{
        CLASS,
        METHOD,
        FIELD
    }
    
    /**
     * The associated jarp.
     */
    public final Jarp assoc;
    /**
     * The keys name.
     */
    public final String keyname;
    /**
     * The keys type.
     */
    public final KeyType keyType;
    
    /**
     * 
     * @param assoc The associated jarp.
     * @param keyname The keys name.
     * @param keyType The keys type.
     */
    public Key(Jarp assoc, String keyname, KeyType keyType){
        this.assoc = assoc;
        this.keyname = keyname;
        this.keyType = keyType;
    }
    
    /**
     * Matches a keyname and type against this key.
     * @param keyname The keyname to match.
     * @param keyType The key type to match.
     * @return Whether or not the keys match.
     */
    public boolean matches(String keyname, KeyType keyType){
        return keyType == this.keyType && keyname.equals(this.keyname);
    }
    
}
